package com.example.online_exam_system.service.impl;

import com.example.online_exam_system.dto.RegisterDto;
import com.example.online_exam_system.entity.Student;
import com.example.online_exam_system.dao.StudentDao;
import com.example.online_exam_system.service.StudentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (Student)表服务实现类
 *
 * @author lianglong@asiainfo.com
 * @since 2021-11-25 14:38:43
 */
@Service("studentService")
public class StudentServiceImpl implements StudentService {
    @Resource
    private StudentDao studentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param studentid 主键
     * @return 实例对象
     */
    @Override
    public Student queryById(Object studentid) {
        return this.studentDao.queryById(studentid);
    }

    @Override
    public List<Map<String, Object>> queryByuserName(Map<String,Object> inParam) {
        return this.studentDao.queryByuserName(inParam);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Student> queryAllByLimit(int offset, int limit) {
        return this.studentDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param student 实例对象
     * @return 实例对象
     */
    @Override
    public Student insert(Student student) {
        this.studentDao.insert(student);
        return student;
    }

    @Override
    public int insert(RegisterDto registerDto) {
        return this.studentDao.insert(registerDto);
    }

    /**
     * 修改数据
     *
     * @param student 实例对象
     * @return 实例对象
     */
    @Override
    public Student update(Student student) {
        this.studentDao.update(student);
        return this.queryById(student.getStudentid());
    }

    /**
     * 通过主键删除数据
     *
     * @param studentid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Object studentid) {
        return this.studentDao.deleteById(studentid) > 0;
    }

    @Override
    public Map<String, Object> getStudentInfo(String Username) {
        return this.studentDao.getStudentInfo(Username);
    }

    @Override
    public String getPassword(Map<String, Object> inParam) {
        return studentDao.getPassword(inParam);
    }

    @Override
    public int updateStudentInfo(Map<String, Object> inParam) {
        return studentDao.updateStudentInfo(inParam);
    }

    @Override
    public List<Map<String, Object>> getStuAll() {
        return studentDao.getStuAll();
    }
}
